uniform mat4 toCameraEC;
varying vec3 ec;
varying vec3 normal;

void main()
{
	// Transform from the 'light camera' EC to the real camera EC
	// gl_ModelViewMatrix is column major
	vec4 temp = gl_ModelViewMatrix * gl_Vertex;
	// toCameraEC is row major...from OSG
	temp *= toCameraEC;
	ec = temp.xyz;
	// TODO is this the correct normal
	// NO!! just happens to be right for the simple scene
	//normal = gl_NormalMatrix * gl_Normal;
	normal = gl_Normal;

#if 1
	gl_Position = ftransform();		
#else 

/*
    vec4 p = gl_ProjectionMatrix * gl_ModelViewMatrix * gl_Vertex;
    p = p/p.w;
    float r = sqrt( (p.x * p.x) + (p.y * p.y) );
    float phi = atan( p.y, p.x );
    //float theta = r * (4.71238898)/2.0;
    float theta = r * (3.14159265)/2.0;
    gl_Position = vec4( sin(theta)*cos(phi), sin(theta)*sin(phi), p.z, 1.0 );
    //gl_Position = vec4( r*cos(phi), r*sin(phi), p.z, 1.0 );

*/
	vec3 n = (gl_ModelViewMatrix * gl_Vertex).xyz;
	n = normalize(n);
	n.z = (gl_ModelViewMatrix*gl_Vertex).z;
	vec4 proj = ftransform();
	gl_Position = gl_ProjectionMatrix * vec4(n, 1.0); //vec4(temp.x, temp.y, proj.z, 1.0);

/*
	vec4 n = gl_ModelViewMatrix * gl_Vertex;
    float depth = n.z;//length(n);
    float zdir = sign(n.z);
	n = normalize(n);
    n.z = depth;
    n.w = 1.0;//-zdir;
	//gl_Position = gl_ProjectionMatrix * n;
	gl_Position = n;
*/



#endif



}
